package com.collection;

import java.util.AbstractCollection;
import java.util.Iterator;

//AbstrctCollection类提供了Collection的默认实现，一般情况下，继承AbstrctCollection即可
public class CollectionSequence extends AbstractCollection<Integer> {

	private Integer[] arr = { 1, 2, 3, 4 };

	@Override
	public Iterator<Integer> iterator() {
		return new Iterator<Integer>() {

			private int index = 0;

			@Override
			public boolean hasNext() {
				return index < arr.length;
			}

			@Override
			public Integer next() {
				return arr[index++];
			}

			@Override
			public void remove() {
				throw new UnsupportedOperationException();
			}
		};
	}

	@Override
	public int size() {
		return arr.length;
	}

	public static void main(String[] args) {
		CollectionSequence c = new CollectionSequence();
		InterfaceVsIterator.display(c.iterator());
		InterfaceVsIterator.display(c);
	}

}
